#include "StdAfx.h"
#include "SProgressUI.h"

CSProgressUI::CSProgressUI(void)
	: m_pProgress(NULL)
// 	, m_dwBackColor(0xFF16202A)
	, m_ForeColor(0xFFFF0000)
	, m_nProgress(10)
{
	m_pProgress = new CContainerUI;
	CContainerUI * pUI = new CContainerUI;
	m_pProgress->SetBkColor(0xFFFF0000);
	Add(m_pProgress);
	Add(pUI);
}

void CSProgressUI::SetForeColor(COLORREF & color)
{
	m_ForeColor = color;
	m_pProgress->SetBkColor(m_ForeColor);
}

void CSProgressUI::SetProgress(UINT & Progress)
{
	m_nProgress = Progress;
}

void CSProgressUI::SetPos(RECT rc)
{
	int nWidth = rc.right - rc.left;
	SetInternVisible(false);
	m_pProgress->SetFixedWidth(nWidth * m_nProgress / 100);
	SetInternVisible(true);
	CHorizontalLayoutUI::SetPos(rc);
}

void CSProgressUI::DoPaint(HDC hDC, const RECT& rcPaint)
{
	CHorizontalLayoutUI::DoPaint(hDC,rcPaint);
}

void CSProgressUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
{
	if (_tcscmp(pstrName, _T("forecolor")) == 0) 
	{
		while( *pstrValue > _T('\0') && *pstrValue <= _T(' ') ) pstrValue = ::CharNext(pstrValue);
		if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
		LPTSTR pstr = NULL;
		DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
		SetForeColor(clrColor);
	}
	else CHorizontalLayoutUI::SetAttribute(pstrName,pstrValue);
}